package numbles.controller;

import java.util.Set;

import numbles.model.Coordinates;
import numbles.model.Grid;
import numbles.model.Move;
import numbles.model.MovementType;

public class MovementEvent {

	private MovementType movementType;

	private Set<Coordinates> deletions;

	private Set<Move> moves;

	private Grid afterGrid;
	
	private Coordinates newCoordinates;

	public MovementEvent(MovementType movementType,
			Set<Coordinates> deletions, Set<Move> moves, Grid afterGrid) {
		super();
		this.movementType = movementType;
		this.deletions = deletions;
		this.moves = moves;
		this.afterGrid = afterGrid;
	}
	
	public MovementEvent(MovementType movementType,
			Coordinates newCoordinates, Grid afterGrid) {
		super();
		this.movementType = movementType;
		this.afterGrid = afterGrid;
		this.newCoordinates = newCoordinates;
	}

	public MovementType getMovementType() {
		return movementType;
	}

	public void setMovementType(MovementType movementType) {
		this.movementType = movementType;
	}

	public Set<Coordinates> getDeletions() {
		return deletions;
	}

	public void setDeletions(Set<Coordinates> deletions) {
		this.deletions = deletions;
	}

	public Set<Move> getMoves() {
		return moves;
	}

	public void setMoves(Set<Move> moves) {
		this.moves = moves;
	}

	public Grid getAfterGrid() {
		return afterGrid;
	}

	public void setAfterGrid(Grid afterGrid) {
		this.afterGrid = afterGrid;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		switch(movementType) {
		case NUMBLE_FALL:
			sb.append(" --- numble " + afterGrid.getNumbleAt(newCoordinates).getNumber() + " fall on col " + newCoordinates.getX());
			break;
		case DELETION:
			if(deletions != null && !deletions.isEmpty()) {
				sb.append(" ---- deletion : ");
				for(Coordinates c : deletions) 
					sb.append(c.toString() + " :: ");
			}
			if(moves != null && !moves.isEmpty()) {
				if(deletions != null && !deletions.isEmpty()) sb.append("\n");
				sb.append(" ---- moves : ");
				for(Move m : moves) {
					sb.append(m.toString()+" :: ");
				}
			}
			break;
		case NEW_LINE:
			sb.append(" --- new line : ");
			for(int i = 0 ; i < afterGrid.getWidth() ; i++)
				sb.append(" " + afterGrid.getNumbleAt(i, afterGrid.getHeight() -1 ).getNumber() + " ");
			break;
		case SHIFT:
			sb.append(" ---- shift");
			break;
		} 
		return sb.toString();
	}
}
